package io.gitee.zhangbinhub.admin.route.init

import io.gitee.zhangbinhub.acp.boot.init.AcpInitialization
import io.gitee.zhangbinhub.acp.boot.log.LogAdapter
import io.gitee.zhangbinhub.admin.route.service.InitDataService
import io.gitee.zhangbinhub.admin.route.service.RouteService
import org.springframework.stereotype.Component

@Component
class DataInitialization(
    private val logAdapter: LogAdapter,
    private val routeService: RouteService,
    private val initDataService: InitDataService
) : AcpInitialization {
    override val name: String
        get() = "Data Initialization"

    override val order: Int
        get() = 1

    override fun doInit() {
        routeService.getRouteListByRouteIdList(listOf(InitDataService.WORK_FLOW_SERVER_API_ROUTE_ID)).let { routeList ->
            if (routeList.isEmpty()) {
                logAdapter.info(">>>>>>>>>>>>>>>>>>>> begin init route data...")
                initDataService.doInitRoute()
                logAdapter.info(">>>>>>>>>>>>>>>>>>>> init route data has finished!")
            }
        }
    }
}